from pydantic import BaseModel
from models.homepage import HomepageCarousel
from fastapi import FastAPI, HTTPException, APIRouter
from typing import List

router = APIRouter(prefix="/homepage", tags=["首页与轮播图API"])

class CarouselImage(BaseModel):
    id: int
    images: str

# 获取轮播图列表
@router.get("/carousel", response_model=List[CarouselImage])
async def get_carousel_images():
    try:
        carousel_items = await HomepageCarousel.all()
        return carousel_items
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"获取轮播图失败: {str(e)}")